********************DATA PREP********************
cd "C:\RCFS Data"
clear all
set more off
use "Compustat data.dta", clear

winsor2 roa td2ta q capx2ta divs2ta cash2ta logat tang, replace cuts(1 99)

summ roa
gen roa_sd=r(sd)
gen roa_mean=r(mean)

summ td2ta
gen td2ta_sd=r(sd)
gen td2ta_mean=r(mean)

summ q
gen q_sd=r(sd)
gen q_mean=r(mean)

summ capx2ta
gen capx2ta_sd=r(sd)
gen capx2ta_mean=r(mean)

summ divs2ta
gen divs2ta_sd=r(sd)
gen divs2ta_mean=r(mean)

summ cash2ta
gen cash2ta_sd=r(sd)
gen cash2ta_mean=r(mean)

summ logat
gen logat_sd=r(sd)
gen logat_mean=r(mean)

summ tang
gen tang_sd=r(sd)
gen tang_mean=r(mean)

***INDUSTRY FE***
*Profitability
areg roa logat td2ta q i.year, absorb(sic2) cluster(gvkey)
gen logat_coeff=_b[logat]
gen td2ta_coeff=_b[td2ta]
gen q_coeff=_b[q]

di "size esmu: " abs(logat_coeff*logat_sd/roa_mean)
di "size essigma: " abs(logat_coeff*logat_sd/roa_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/roa_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/roa_sd)
di "value esmu: " abs(q_coeff*q_sd/roa_mean)
di "value essigma: " abs(q_coeff*q_sd/roa_sd)

drop logat_coeff td2ta_coeff q_coeff

*Value
areg q logat capx2ta td2ta roa i.year, absorb(sic2) cluster(gvkey)
gen logat_coeff=_b[logat]
gen capx2ta_coeff=_b[capx2ta]
gen td2ta_coeff=_b[td2ta]
gen roa_coeff=_b[roa]

di "size esmu: " abs(logat_coeff*logat_sd/q_mean)
di "size essigma: " abs(logat_coeff*logat_sd/q_sd)
di "inv esmu: " abs(capx2ta_coeff*capx2ta_sd/q_mean)
di "inv essigma: " abs(capx2ta_coeff*capx2ta_sd/q_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/q_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/q_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/q_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/q_sd)

drop logat_coeff capx2ta_coeff td2ta_coeff roa_coeff

*Leverage
areg td2ta logat roa q tang capx2ta i.year, absorb(sic2) cluster(gvkey)
gen logat_coeff=_b[logat]
gen roa_coeff=_b[roa]
gen q_coeff=_b[q]
gen tang_coeff=_b[tang]
gen capx2ta_coeff=_b[capx2ta]

di "size esmu: " abs(logat_coeff*logat_sd/td2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/td2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/td2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/td2ta_sd)
di "val esmu: " abs(q_coeff*q_sd/td2ta_mean)
di "val essigma: " abs(q_coeff*q_sd/td2ta_sd)
di "tang esmu: " abs(tang_coeff*tang_sd/td2ta_mean)
di "tang essigma: " abs(tang_coeff*tang_sd/td2ta_sd)
di "inv esmu: " abs(capx2ta_coeff*capx2ta_sd/td2ta_mean)
di "inv essigma: " abs(capx2ta_coeff*capx2ta_sd/td2ta_sd)

drop logat_coeff capx2ta_coeff tang_coeff roa_coeff q_coeff

*Investment
areg capx2ta logat q roa td2ta i.year, absorb(sic2) cluster(gvkey)
gen logat_coeff=_b[logat]
gen q_coeff=_b[q]
gen roa_coeff=_b[roa]
gen td2ta_coeff=_b[td2ta]

di "size esmu: " abs(logat_coeff*logat_sd/capx2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/capx2ta_sd)
di "q esmu: " abs(q_coeff*q_sd/capx2ta_mean)
di "q essigma: " abs(q_coeff*q_sd/capx2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/capx2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/capx2ta_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/capx2ta_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/capx2ta_sd)

drop logat_coeff q_coeff roa_coeff td2ta_coeff

*Payouts
areg divs2ta logat roa q td2ta i.year, absorb(sic2) cluster(gvkey)
gen logat_coeff=_b[logat]
gen roa_coeff=_b[roa]
gen q_coeff=_b[q]
gen td2ta_coeff=_b[td2ta]

di "size esmu: " abs(logat_coeff*logat_sd/divs2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/divs2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/divs2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/divs2ta_sd)
di "q esmu: " abs(q_coeff*q_sd/divs2ta_mean)
di "q essigma: " abs(q_coeff*q_sd/divs2ta_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/divs2ta_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/divs2ta_sd)

drop logat_coeff roa_coeff q_coeff td2ta_coeff

*Cash
areg cash2ta logat roa q td2ta capx2ta divs2ta i.year, absorb(sic2) cluster(gvkey)
gen logat_coeff=_b[logat]
gen roa_coeff=_b[roa]
gen q_coeff=_b[q]
gen td2ta_coeff=_b[td2ta]
gen capx2ta_coeff=_b[capx2ta]
gen divs2ta_coeff=_b[divs2ta]

di "size esmu: " abs(logat_coeff*logat_sd/cash2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/cash2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/cash2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/cash2ta_sd)
di "q esmu: " abs(q_coeff*q_sd/cash2ta_mean)
di "q essigma: " abs(q_coeff*q_sd/cash2ta_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/cash2ta_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/cash2ta_sd)
di "inv esmu: " abs(capx2ta_coeff*capx2ta_sd/cash2ta_mean)
di "inv essigma: " abs(capx2ta_coeff*capx2ta_sd/cash2ta_sd)
di "payout esmu: " abs(divs2ta_coeff*divs2ta_sd/cash2ta_mean)
di "payout essigma: " abs(divs2ta_coeff*divs2ta_sd/cash2ta_sd)

drop logat_coeff roa_coeff q_coeff td2ta_coeff capx2ta_coeff divs2ta_coeff



***FIRM FE***
*Profitability
areg roa logat td2ta q i.year, absorb(gvkey) cluster(gvkey)
gen logat_coeff=_b[logat]
gen td2ta_coeff=_b[td2ta]
gen q_coeff=_b[q]

di "size esmu: " abs(logat_coeff*logat_sd/roa_mean)
di "size essigma: " abs(logat_coeff*logat_sd/roa_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/roa_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/roa_sd)
di "value esmu: " abs(q_coeff*q_sd/roa_mean)
di "value essigma: " abs(q_coeff*q_sd/roa_sd)

drop logat_coeff td2ta_coeff q_coeff

*Value
areg q logat capx2ta td2ta roa i.year, absorb(gvkey) cluster(gvkey)
gen logat_coeff=_b[logat]
gen capx2ta_coeff=_b[capx2ta]
gen td2ta_coeff=_b[td2ta]
gen roa_coeff=_b[roa]

di "size esmu: " abs(logat_coeff*logat_sd/q_mean)
di "size essigma: " abs(logat_coeff*logat_sd/q_sd)
di "inv esmu: " abs(capx2ta_coeff*capx2ta_sd/q_mean)
di "inv essigma: " abs(capx2ta_coeff*capx2ta_sd/q_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/q_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/q_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/q_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/q_sd)

drop logat_coeff capx2ta_coeff td2ta_coeff roa_coeff

*Leverage
areg td2ta logat roa q tang capx2ta i.year, absorb(gvkey) cluster(gvkey)
gen logat_coeff=_b[logat]
gen roa_coeff=_b[roa]
gen q_coeff=_b[q]
gen tang_coeff=_b[tang]
gen capx2ta_coeff=_b[capx2ta]

di "size esmu: " abs(logat_coeff*logat_sd/td2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/td2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/td2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/td2ta_sd)
di "val esmu: " abs(q_coeff*q_sd/td2ta_mean)
di "val essigma: " abs(q_coeff*q_sd/td2ta_sd)
di "tang esmu: " abs(tang_coeff*tang_sd/td2ta_mean)
di "tang essigma: " abs(tang_coeff*tang_sd/td2ta_sd)
di "inv esmu: " abs(capx2ta_coeff*capx2ta_sd/td2ta_mean)
di "inv essigma: " abs(capx2ta_coeff*capx2ta_sd/td2ta_sd)

drop logat_coeff capx2ta_coeff tang_coeff roa_coeff q_coeff

*Investment
areg capx2ta logat q roa td2ta i.year, absorb(gvkey) cluster(gvkey)
gen logat_coeff=_b[logat]
gen q_coeff=_b[q]
gen roa_coeff=_b[roa]
gen td2ta_coeff=_b[td2ta]

di "size esmu: " abs(logat_coeff*logat_sd/capx2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/capx2ta_sd)
di "q esmu: " abs(q_coeff*q_sd/capx2ta_mean)
di "q essigma: " abs(q_coeff*q_sd/capx2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/capx2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/capx2ta_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/capx2ta_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/capx2ta_sd)

drop logat_coeff q_coeff roa_coeff td2ta_coeff

*Payouts
areg divs2ta logat roa q td2ta i.year, absorb(gvkey) cluster(gvkey)
gen logat_coeff=_b[logat]
gen roa_coeff=_b[roa]
gen q_coeff=_b[q]
gen td2ta_coeff=_b[td2ta]

di "size esmu: " abs(logat_coeff*logat_sd/divs2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/divs2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/divs2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/divs2ta_sd)
di "q esmu: " abs(q_coeff*q_sd/divs2ta_mean)
di "q essigma: " abs(q_coeff*q_sd/divs2ta_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/divs2ta_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/divs2ta_sd)

drop logat_coeff roa_coeff q_coeff td2ta_coeff

*Cash
areg cash2ta logat roa q td2ta capx2ta divs2ta i.year, absorb(gvkey) cluster(gvkey)
gen logat_coeff=_b[logat]
gen roa_coeff=_b[roa]
gen q_coeff=_b[q]
gen td2ta_coeff=_b[td2ta]
gen capx2ta_coeff=_b[capx2ta]
gen divs2ta_coeff=_b[divs2ta]

di "size esmu: " abs(logat_coeff*logat_sd/cash2ta_mean)
di "size essigma: " abs(logat_coeff*logat_sd/cash2ta_sd)
di "prof esmu: " abs(roa_coeff*roa_sd/cash2ta_mean)
di "prof essigma: " abs(roa_coeff*roa_sd/cash2ta_sd)
di "q esmu: " abs(q_coeff*q_sd/cash2ta_mean)
di "q essigma: " abs(q_coeff*q_sd/cash2ta_sd)
di "lev esmu: " abs(td2ta_coeff*td2ta_sd/cash2ta_mean)
di "lev essigma: " abs(td2ta_coeff*td2ta_sd/cash2ta_sd)
di "inv esmu: " abs(capx2ta_coeff*capx2ta_sd/cash2ta_mean)
di "inv essigma: " abs(capx2ta_coeff*capx2ta_sd/cash2ta_sd)
di "payout esmu: " abs(divs2ta_coeff*divs2ta_sd/cash2ta_mean)
di "payout essigma: " abs(divs2ta_coeff*divs2ta_sd/cash2ta_sd)

drop logat_coeff roa_coeff q_coeff td2ta_coeff capx2ta_coeff divs2ta_coeff
